package com.yuw.fun;

public class Test1 {

	public static void main(String[] args) {
		// 调用变长参数
		System.out.println("=====================");
		System.out.println("调用变长参数方法：");
		shopping(99, "小明", "张三1", "王五1", "赵六1");
		
		System.out.println("=====================");
		System.out.println("以数组的形式调用变长参数方法：");
		String[] strOtherF = { "张三2", "王五2", "赵六2" };
		shopping(88, "小明", strOtherF);
		
		System.out.println("=====================");
		System.out.println("变长参数可以为0个：");
		shopping(77, "小明");
	}

	/**
	 * 购物
	 * 
	 * @param strFrieds
	 *            形参
	 */
	private static void shopping(double costMoney) {
		System.out.println("I am shopping with money of " + costMoney);
	}

	/**
	 * 购物
	 * 
	 * @param strFrieds
	 * @param costMoney
	 */
	private static void shopping(double costMoney, String strFrieds) {
		System.out.println("此处调用的是非变长参数方法");
		System.out.println("I am shopping with boyfriend " + strFrieds + ",and costing Money of " + costMoney);
	}

	/**
	 * 变长参数方法 购物
	 * 
	 * @param strFrieds
	 * @param costMoney
	 */
	private static void shopping(double costMoney, String strFrieds, String... strOtherFrieds) {
		// 如何获取变长参数的内容
		// 变长参数就是一个该数据类型的数组
		System.out.println("变长参数就当成数组进行遍历即可：");
		if (strOtherFrieds != null) {
			for (String str : strOtherFrieds) {
				System.out.print(" " + str);
			}
			// 换行
			System.out.println();
		}
		System.out.println("I am shopping with boyfriend " + strFrieds + ",and costing Money of " + costMoney);
	}

}
